﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="App.xaml.cs" company="">
//   
// </copyright>
// <summary>
//   Interaction logic for App.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace F5.BigIp.LocalTrafficManager.UI
{
    using System;
    using System.Windows;
    using System.Windows.Threading;

    using F5.BigIp.LocalTrafficManager.UI.Infrastructure;
    using F5.BigIp.LocalTrafficManager.UI.ViewModels;

    /// <summary>
    ///     Interaction logic for the WPF application
    /// </summary>
    public partial class App
    {
        #region Constructors and Destructors

        /// <summary>Initializes a new instance of the <see cref="App"/> class.</summary>
        public App()
        {
            Bootstrapper.Initialize();
        }

        #endregion

        #region Methods

        protected override void OnStartup(StartupEventArgs e)
        {
            var mainViewModel = TinyIoCContainer.Current.Resolve<IMainViewModel>();

            if (mainViewModel == null)
            {
                return;
            }

            var window = mainViewModel.Window;

            if (window != null)
            {
                window.ShowDialog();
            }
        }

        /// <summary>The application_ dispatcher unhandled exception.</summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.Message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error);

            if (e.Exception is InvalidOperationException)
            {
                e.Handled = true;
            }
        }

        #endregion
    }
}